#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "yuvloader.h"
#include "frameprovider.h"

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    FrameProvider* provider = new FrameProvider();
    YUVLoader source;

    // Set the correct format for the video surface (Make sure your selected format is supported by the surface)
    provider->setFormat(320, 180, QVideoFrame::Format_YUV420P);

    // Connect your frame source with the provider
    QObject::connect(&source, &YUVLoader::newFrameAvailable, provider, &FrameProvider::onNewVideoContentReceived);

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("frameProvider", provider);

    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);    

    return app.exec();
}
